package com.dao.Journal.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.dao.Journal.JournalDao;
import com.entity.User;
import com.entity.journal.Journal;
import com.entity.journal.JournalCategory;
import com.entity.journal.JournalComment;
import com.entity.journal.JournalVisitor;

@Repository("journalDao")
public class JournalDaoImpl extends HibernateDaoSupport implements JournalDao {

	Session session = null;
	
	@SuppressWarnings("unchecked")
	public List<JournalComment> getJournalCommentList(Integer journalId)
			throws Exception {
		session = getSession();
		Criteria c = session.createCriteria(JournalComment.class);
		c.add(Restrictions.eq("journalId", journalId));
		return (List<JournalComment>)c.list();
	}

	@SuppressWarnings("unchecked")
	public List<Journal> getJournalList(Integer userId) throws Exception {
		session = getSession();
		Criteria c = session.createCriteria(Journal.class);
		c.add(Restrictions.eq("userId", userId));
		return (List<Journal>)c.list();
	}

	@SuppressWarnings("unchecked")
	public List<JournalVisitor> getVisitorList(Integer journalId) throws Exception {
		session = getSession();
		Criteria c = session.createCriteria(JournalVisitor.class);
		c.add(Restrictions.eq("journalId", journalId));
		return (List<JournalVisitor>)c.list();
	}
}
